import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: 'Dashboard', icon: 'dashboard', affix: true }
      }
    ]
  },
  // 顾客管理
  {
    path: '/customer-manager',
    component: Layout,
    children: [
      {
        path: 'index',
        component: () => import('@/views/customer-manager/index'),
        name: 'Customer-manager',
        meta: { title: '顾客管理', icon: 'documentation', affix: true }
      }
    ]
  },
  // 产品管理
  {
    path: '/product-manager',
    component: Layout,
    children: [
      {
        path: 'index',
        component: () => import('@/views/product-manager/index'),
        name: 'Product-manager',
        meta: { title: '产品管理', icon: 'guide', affix: true }
      }
    ]
  },
  // 产品详情
  {
    path: '/product-details',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/product-manager/details'),
        name: 'Product-details',
        meta: { title: '产品详情' }
      }
    ]
  },
  // 栏目管理
  {
    path: '/category-manager',
    component: Layout,
    children: [
      {
        path: 'index',
        component: () => import('@/views/category-manager/index'),
        name: 'Category-manager',
        meta: { title: '栏目管理', icon: 'icon', affix: true }
      }
    ]
  },
  // 订单管理
  {
    path: '/order-manager',
    component: Layout,
    children: [
      {
        path: 'index',
        component: () => import('@/views/order-manager/index'),
        name: 'Order-manager',
        meta: { title: '订单管理', icon: 'example', affix: true }
      }
    ]
  },
  // 订单管理的详情页面
  {
    path: '/orderManger-details',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/order-manager/details'),
        name: 'Order-manager',
        meta: { title: '订单详情' }
      }
    ]
  },
  // 员工管理
  {
    path: '/staff-manager',
    component: Layout,
    children: [
      {
        path: 'index',
        component: () => import('@/views/staff-manager/index'),
        name: 'Staff-manager',
        meta: { title: '员工管理', icon: 'tab', affix: true }
      }
    ]
  },
  {
    path: '/waiters-details',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'index',
        name: 'Waiters-details',
        component: () => import('@/views/staff-manager/details'),
        meta: { title: '员工详情', addix: true }

      }
    ]
  },
  {
    path: '/innerdetails',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'index',
        name: 'Innerdetails',
        component: () => import('@/views/staff-manager/innerdetails'),
        meta: { title: '员工详情2', addix: true }

      }
    ]
  },
  // 评论管理
  {
    path: '/comment-manager',
    component: Layout,
    children: [
      {
        path: 'index',
        component: () => import('@/views/comment-manager/index'),
        name: 'Comment-manager',
        meta: { title: '评论管理', icon: 'people', affix: true }
      }
    ]
  },
  // 顾客详情
  {
    path: '/customer-details',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/customer-manager/details'),
        name: 'Customer-details',
        meta: { title: '详情页面', affix: true }
      }
    ]
  },
  // 顾客管理的订单信息的详情页面
  {
    path: '/customerOrder-details',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/customer-manager/orderdetails.vue'),
        name: 'CustomerOrder-details',
        meta: { title: '订单页面' }
      }
    ]
  }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [

  {
    path: '/check-manager', // example
    component: Layout,
    redirect: '/check-manager/list',
    name: 'Check-manager',
    meta: {
      title: '审核大厅',
      icon: 'user'
    },
    children: [
      {
        path: 'stuff-check', // create
        component: () => import('@/views/check-manager/stuff-check'),
        name: 'stuffCheck',
        meta: { title: '员工审核' }
      },

      {
        path: 'money-check',
        component: () => import('@/views/check-manager/money-check'),
        name: 'moneyCheck',
        meta: { title: '提现审核' }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
